package sortAlgorithm;

/**
 * 冒泡排序
 * 每次从未排序序列中得到一个最大值放在数组最后
 */
public class BubbleSort {

  public static void bubbleSort(int[] nums) {
    if (nums == null || nums.length <= 1) {
      return;
    }
    for (int i = 0; i < nums.length; ++i) {
      for (int j = 0; j < nums.length - 1 - i; ++j) {
        if (nums[j] > nums[j + 1]) {
          int tmp = nums[j];
          nums[j] = nums[j + 1];
          nums[j + 1] = tmp;
        }
      }
    }
  }
}
